/**
 * ------------------------------------------------------------------------------------------
 * Copyright (c): Company, 2012 This software is the
 * proprietary information of FHWS, Würzburg All Right Reserved.
 * ------------------------------------------------------------------------------------------
 *
 *
 * @project: Vorlesungplan
 * @copyright FHWS 2012
 * @link       http://mussnocheingeragenwerden.de
 * @package    tt.model
 *
 * SVN revision information:
 *
 * @version $Rev$:
 * @author $Author$:
 * @date $Date$:
 */

package tt.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@Table(name = "courseschedule")
@XmlRootElement
@NamedQueries(
{
   @NamedQuery(name = "Courseschedule.findAll", query = "SELECT c FROM Courseschedule c"),
   @NamedQuery(name = "Courseschedule.findByIdcourseschedule", query = "SELECT c FROM Courseschedule c WHERE c.idcourseschedule = :idcourseschedule"),
   @NamedQuery(name = "Courseschedule.findByTimestampschedule", query = "SELECT c FROM Courseschedule c WHERE c.timestampschedule = :timestampschedule"),
   @NamedQuery(name = "Courseschedule.deleteByIdcourseschedule", query = "delete from Courseschedule c where c.idcourseschedule like :idcourseschedule")
})
public class Courseschedule implements Serializable
{

   private static final long serialVersionUID = 1L;
   @Id
   @Basic(optional = false)
   @Size(min = 1, max = 45)
   @Column(name = "idcourseschedule")
   private String idcourseschedule;
   @Column(name = "timestampschedule")
   @Temporal(TemporalType.TIMESTAMP)
   private Date timestampschedule;
   @JoinTable(name = "courseschedule_has_lecturedate", joinColumns =
   {
      @JoinColumn(name = "CourseSchedule_idcourseSchedule", referencedColumnName = "idcourseschedule")
   }, inverseJoinColumns =
   {
      @JoinColumn(name = "LectureDate_idlecturedate", referencedColumnName = "idlecturedate")
   })
   @ManyToMany
   private Collection<Lecturedate> lecturedateCollection;

   public Courseschedule()
   {
   }

   public Courseschedule(String idcourseschedule)
   {
      this.idcourseschedule = idcourseschedule;
   }

   public String getIdcourseschedule()
   {
      return idcourseschedule;
   }

   public void setIdcourseschedule(String idcourseschedule)
   {
      this.idcourseschedule = idcourseschedule;
   }

   public Date getTimestampschedule()
   {
      return timestampschedule;
   }

   public void setTimestampschedule(Date timestampschedule)
   {
      this.timestampschedule = timestampschedule;
   }

   @XmlTransient
   public Collection<Lecturedate> getLecturedateCollection()
   {
      Collections.sort((List<Lecturedate>) lecturedateCollection);
      return lecturedateCollection;
   }

   public void setLecturedateCollection(Collection<Lecturedate> lecturedateCollection)
   {
      this.lecturedateCollection = lecturedateCollection;
   }

   @Override
   public int hashCode()
   {
      int hash = 0;
      hash += (idcourseschedule != null ? idcourseschedule.hashCode() : 0);
      return hash;
   }

   @Override
   public boolean equals(Object object)
   {
      // TODO: Warning - this method won't work in the case the id fields are not set
      if (!(object instanceof Courseschedule))
      {
         return false;
      }
      Courseschedule other = (Courseschedule) object;
      if ((this.idcourseschedule == null && other.idcourseschedule != null) || (this.idcourseschedule != null && !this.idcourseschedule.equals(other.idcourseschedule)))
      {
         return false;
      }
      return true;
   }

   @Override
   public String toString()
   {
      return "tt.model.Courseschedule[ idcourseschedule=" + idcourseschedule + " ]";
   }
}
